Skip to content

fix: stale order map on pooled headerSorter breaks orderless header sorting - #18

Open
burruplambert wants to merge 1 commit into
bogdanfinn:masterfrom
burruplambert:fix-stale-header-sorter-order
Open

fix: stale order map on pooled headerSorter breaks orderless header sorting#18
burruplambert wants to merge 1 commit into
bogdanfinn:masterfrom
burruplambert:fix-stale-header-sorter-order

Conversation

@burruplambert

@burruplambert burruplambert commented Jul 28, 2026

Copy link
Copy Markdown

Summary

headerSorter instances are pooled and shared between SortedKeyValuesBy and SortedKeyValues, but SortedKeyValues never clears hs.order. A sorter previously used for an ordered sort (any header write with a Header-Order: key) keeps its order map, and a later orderless sort on the same pooled sorter applies that stale order instead of sorting lexicographically.

The wrong order shows up whenever the new header's lowercased keys collide with entries in the stale order map - matched keys jump to the front in the stale order's positions while the rest fall back to lexicographic. Since header order is the whole point of this fork, silently reordering headers based on a previous request's order map seems worth fixing.

Changes

  • header.go - reset hs.order = nil in SortedKeyValues before sorting
  • header_test.go - regression test that runs an ordered sort, returns the sorter to the pool, then verifies an orderless sort is lexicographic

Note: #17, which also touched SortedKeyValues state handling, was closed and split into focused PRs (the decompression part is now #19). This fix stands alone either way; a follow-up PR improving the sorter's comparison performance will be cross-referenced here when it opens.

headerSorter instances are pooled and shared between SortedKeyValuesBy
and SortedKeyValues, but SortedKeyValues never cleared hs.order. A
sorter previously used for an ordered sort would keep its order map and
apply it to a later orderless sort, producing the wrong header order
whenever the new header's lowercased keys collide with entries in the
stale order map.

Reset hs.order before sorting in SortedKeyValues and add a regression
test.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant